package com.betterjr.modules.risk.loan.entity;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.selectkey.SerialGenerator;
import com.betterjr.modules.customer.entity.CustMechBankAccount;
import com.betterjr.modules.risk.loan.data.LoanTransactionRelationConstantCollections;

@Access(AccessType.FIELD)
@Entity
@Table(name = "t_scf_loanproject_bank")
public class LoanProjectBank implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = 1753879191476553446L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     * 贷款项目id
     */
    @Column(name = "L_LOAN_ID", columnDefinition = "INTEGER")
    @MetaData(value = "贷款项目id", comments = "贷款项目id")
    private Long loanId;

    /**
     * 类型 1：供应商监管账户 2供应商可归集账户 3供应商收款帐号 4供应商 扣账帐号本金 5供应商扣款账户利息  6资金方放款账户 7资金方收款账户本金 8资金方收款账户利息 9平台服务费供应商付款账户
     */
    @Column(name = "C_TYPE", columnDefinition = "VARCHAR")
    @MetaData(value = "类型 1：供应商监管账户 2供应商可归集账户 3供应商收款帐号 4供应商 扣账帐号本金 5供应商扣款账户利息  6资金方放款账户 7资金方收款账户本金 8资金方收款账户利息 9平台服务费供应商付款账户", comments = "类型 1：供应商监管账户 2供应商可归集账户 3供应商收款帐号 4供应商 扣账帐号本金 5供应商扣款账户利息  6资金方放款账户 7资金方收款账户本金 8资金方收款账户利息 9平台服务费供应商付款账户")
    private String type;

    /**
     * 银行名称
     */
    @Column(name = "C_BANK_NAME", columnDefinition = "VARCHAR")
    @MetaData(value = "银行名称", comments = "银行名称")
    private String bankName;

    /**
     * 银行帐号
     */
    @Column(name = "C_BANK_ACCO", columnDefinition = "VARCHAR")
    @MetaData(value = "银行帐号", comments = "银行帐号")
    private String bankAcco;

    /**
     * 联行号
     */
    @Column(name = "C_BANK_NO", columnDefinition = "VARCHAR")
    @MetaData(value = "联行号", comments = "联行号")
    private String bankNo;

    /**
     * 银行户名
     */
    @Column(name = "C_BANK_ACCONAME", columnDefinition = "VARCHAR")
    @MetaData(value = "银行户名", comments = "银行户名")
    private String bankAccoName;

    /**
     * 银行表id
     */
    @Column(name = "L_BANK_ID", columnDefinition = "INTEGER")
    @MetaData(value = "银行表id", comments = "银行表id")
    private Long bankId;

    /**
     * 状态 0 失效  1 正常
     */
    @Column(name = "C_BUSINSTATUS", columnDefinition = "VARCHAR")
    @MetaData(value = "状态 0 失效  1 正常", comments = "状态 0 失效  1 正常")
    private String businStatus;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getBankAcco() {
        return bankAcco;
    }

    public void setBankAcco(String bankAcco) {
        this.bankAcco = bankAcco;
    }

    public String getBankAccoName() {
        return bankAccoName;
    }

    public void setBankAccoName(String bankAccoName) {
        this.bankAccoName = bankAccoName;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public String getBusinStatus() {
        return businStatus;
    }

    public void setBusinStatus(String businStatus) {
        this.businStatus = businStatus;
    }

    public String getBankNo() {
        return bankNo;
    }

    public void setBankNo(String bankNo) {
        this.bankNo = bankNo;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (bankAcco == null ? 0 : bankAcco.hashCode());
        result = prime * result + (bankAccoName == null ? 0 : bankAccoName.hashCode());
        result = prime * result + (bankId == null ? 0 : bankId.hashCode());
        result = prime * result + (bankName == null ? 0 : bankName.hashCode());
        result = prime * result + (bankNo == null ? 0 : bankNo.hashCode());
        result = prime * result + (businStatus == null ? 0 : businStatus.hashCode());
        result = prime * result + (id == null ? 0 : id.hashCode());
        result = prime * result + (loanId == null ? 0 : loanId.hashCode());
        result = prime * result + (type == null ? 0 : type.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof LoanProjectBank)) {
            return false;
        }
        final LoanProjectBank other = (LoanProjectBank) obj;
        if (bankAcco == null) {
            if (other.bankAcco != null) {
                return false;
            }
        } else if (!bankAcco.equals(other.bankAcco)) {
            return false;
        }
        if (bankAccoName == null) {
            if (other.bankAccoName != null) {
                return false;
            }
        } else if (!bankAccoName.equals(other.bankAccoName)) {
            return false;
        }
        if (bankId == null) {
            if (other.bankId != null) {
                return false;
            }
        } else if (!bankId.equals(other.bankId)) {
            return false;
        }
        if (bankName == null) {
            if (other.bankName != null) {
                return false;
            }
        } else if (!bankName.equals(other.bankName)) {
            return false;
        }
        if (bankNo == null) {
            if (other.bankNo != null) {
                return false;
            }
        } else if (!bankNo.equals(other.bankNo)) {
            return false;
        }
        if (businStatus == null) {
            if (other.businStatus != null) {
                return false;
            }
        } else if (!businStatus.equals(other.businStatus)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (loanId == null) {
            if (other.loanId != null) {
                return false;
            }
        } else if (!loanId.equals(other.loanId)) {
            return false;
        }
        if (type == null) {
            if (other.type != null) {
                return false;
            }
        } else if (!type.equals(other.type)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "LoanProjectBank [id=" + id + ", loanId=" + loanId + ", type=" + type + ", bankName=" + bankName
                + ", bankAcco=" + bankAcco + ", bankNo=" + bankNo + ", bankAccoName=" + bankAccoName + ", bankId="
                + bankId + ", businStatus=" + businStatus + "]";
    }

    public void saveAddInitValue(String anType) {

        this.setId(SerialGenerator.getLongValue("LoanProjectBank.id"));

        this.setBusinStatus(LoanTransactionRelationConstantCollections.RELATIONS_BUSINSTATUS_OK);

        this.setType(anType);

    }

    public static LoanProjectBank createBank(String anType, CustMechBankAccount anBankAccount, Long anLoanId) {

        final LoanProjectBank bank = new LoanProjectBank();
        bank.saveAddInitValue(anType);
        bank.setBankAcco(anBankAccount.getBankAcco());
        bank.setBankAccoName(anBankAccount.getBankAccoName());
        bank.setBankId(anBankAccount.getId());
        bank.setBankName(anBankAccount.getBankName());
        bank.setBankNo(anBankAccount.getPaySysNum());
        bank.setLoanId(anLoanId);
        return bank;

    }

}
